<?php
m2import('phpinchains/util/BundleTool.php');
m2import('phpinchains/PSPPage.php');
m2import('phpinchains/tagsupport/HtmlInput.php');
m2import('phpinchains/tagsupport/URL.php');
m2import('phpinchains/tagsupport/functions.inc.php');
class default__defaultPSPPage extends phpinchains_PSPPage 
{
   var $validatormap;
   var $objcache;
   var $relativeFilePath = 'view/default/default.psp';
   function validateField (& $env, & $actionform, $fieldname, $validationParam, $validatormapping)
   {
       if (!is_object($this->objcache[$this->validatormap[$validatormapping]['class']]))
       {
           if (isset($this->validatormap[$validatormapping]['class']))           {
               if (m2import($this->validatormap[$validatormapping]['class'].'.php', true))               {
                   $classname = str_replace('/', '_', $this->validatormap[$validatormapping]['class']);
                   $this->objcache[$this->validatormap[$validatormapping]['class']] = new $classname();
               }               else               {
                   print '<strong>Validator not found! The registered validator \''.$this->validatormap[$validatormapping]['class'].'\' with mapping \'\'</strong>';               }
           }           else           {
               print '<strong>Validator not found! Is validator \''.$validatormapping.'\' registered in the action-config.xml of this module? (if conf:validators tag is missing in the config file than even the standard validators are not registered)</strong>';           }
       }
       $this->objcache[$this->validatormap[$validatormapping]['class']]->{$this->validatormap[$validatormapping]['method']}($env, $actionform, $fieldname, $validationParam);
   }

   function validate (& $dispatcher, & $env, & $actionform, $formname, $basedir)
   {
       $this->dispatcher = & $dispatcher;
       include($basedir.'action-config.xml.php');
       $this->validatormap = $validators;
       $validationErrors = & $actionform->getRef('validationErrors');
       $validationErrors->setForm($formname);
       
        $this->validateField($env, $actionform, 'title', '', 'required');

        $this->validateField($env, $actionform, 'description', '', 'required');

       return !$validationErrors->hasErrors();
   }
   function compilePSP ($sfile, $cfile, $viewname)
   {
       $this->dispatcher->compilePSP($sfile, $cfile, $viewname);
   }

   function render (& $dispatcher, & $env, & $actionform, $basedir)
   {
       $this->dispatcher = & $dispatcher;
       
 print "";
if (is_array(__id($env, $actionform, array('threads')))) foreach (__id($env, $actionform, array('threads')) as $thread) {
$actionform->set('thread', $thread);

 print "
    ";
$__url = new phpinchains_tagsupport_URL($env);
$__url->setAction('default::showThread');

 print "
       ";
$__url->addParam('threadid', __id($env, $actionform, array('thread', 'id')));

 print "
       ";
$__url->addParam('doc_id', __id($env, $actionform, array('globalScope', 'doc_id')));

 print "
    ";
$actionform->set('showURL', $__url->toString());

 print "
    <a class=\"threadlisttitle\" href=\"";
print __id($env, $actionform, array('showURL'));
 print "\">";
print htmlspecialchars(__id($env, $actionform, array('thread', 'title')));

 print "</a><br/>
    <span class=\"threaddescription\">";
print htmlspecialchars(__id($env, $actionform, array('thread', 'description')));

 print "</span><br/><br/>
    ";
if (__id($env, $actionform, array('showThreadDelete'))){

 print "
        ";
$__url = new phpinchains_tagsupport_URL($env);
$__url->setAction('default::delThread');

 print "
            ";
$__url->addParam('threadid', __id($env, $actionform, array('thread', 'id')));

 print "
            ";
$__url->addParam('doc_id', __id($env, $actionform, array('globalScope', 'doc_id')));

 print "
        ";
$actionform->set('delURL', $__url->toString());

 print "
        <a href=\"";
print __id($env, $actionform, array('delURL'));
 print "\">";
print htmlspecialchars(__id($env, $actionform, array('thread', 'title')));

 print " l&ouml;schen</a><br/><br/>
    ";
}

 print "
";
}

 print "
";
if (__id($env, $actionform, array('showThreadForm'))){

 print "
<h3>Neuen Thread anlegen:</h3>
    ";
print "<form action=\"?\" name=\"".'addThread'."\" method=\"POST\">";
print "<input type=\"hidden\" name=\"innerAction\" value=\"".'default::addThread'."\"/>";print "<input type=\"hidden\" name=\"__lastView\" value=\"default/default\"/>";print "<input type=\"hidden\" name=\"__formName\" value=\"".'addThread'."\"/>";
 print "
    <input type=\"hidden\" name=\"doc_id\" value=\"";
print __id($env, $actionform, array('globalScope', 'doc_id'));
 print "\"/>
    <table border=\"0\">
        <tr>
            <td>Titel:</td>
            <td>";
print '<input type="'.'text'.'" name="'.'title'.'" size="'.'30'.'" maxlength="'.'100'.'" value="'.__id($env, $actionform, array('title')).'"';
print phpinchains_tagsupport_HtmlInput::getValidationErrorCode($actionform, 'required', 'addThread', 'title', '', '', '', 'border: 1px solid red; background-color: #EFBFAF');
print '/>';

 print "</td>
        </tr>
        <tr>
            <td>Beschreibung:</td>
            <td>";
print '<textarea name="'.'description'.'" cols="'.'50'.'" rows="'.'5'.'"';
print phpinchains_tagsupport_HtmlInput::getValidationErrorCode($actionform, 'required', 'addThread', 'description', '', '', '', 'border: 1px solid red; background-color: #EFBFAF');
print '>';

 print "";
print htmlspecialchars(__id($env, $actionform, array('description')));

 print "";
print '</textarea>';

 print "</td>
        </tr>
        <tr>
            <td colspan=\"2\"><input type=\"submit\" value=\"Eintragen\"></td>
        </tr>
    </table>
    ";
print "</form>";

 print "
";
}

 print "";

   }
   function getJSCode (& $dispatcher, & $env, & $actionform)
   {
       $this->dispatcher = & $dispatcher;
       $jscode = "";
       return $jscode;
   }
}
?>